package com.onluy.sysman.controller;

import com.alibaba.fastjson.JSON;
import com.onluy.frameworkcloud.Param.RspInfo;
import com.onluy.frameworkcloud.tools.utils.RedisUtil;
import com.onluy.sysman.param.RedisParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;

@RefreshScope
@RestController
@EnableCaching
@RequestMapping("/contest18/appsvc/redis")
@Api(value="redis test", description="缓存测试（管理）", position=1 )
public class RedisController {

	protected Logger log =   LoggerFactory.getLogger(this.getClass());


	@Autowired
	RedisUtil redisUtil;


	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmsss");





	@RequestMapping(value={ "/setRedis"},method={RequestMethod.POST })
	@ApiOperation(value="设置redis值", notes="key，value")
	public RspInfo<String> setRedis(@RequestBody RedisParam redisParam ) {
		log.info( "---------------redisParam："+JSON.toJSONString(redisParam) );
		RspInfo<String>  rspInfo= new  RspInfo<String>();
		boolean flg= redisUtil.set(redisParam.getKey(),redisParam.getValue());
		rspInfo.setRspCode(0);
		rspInfo.setRspDesc(flg?"设置成功！":"设置失败！");
		return rspInfo;
	}

	@RequestMapping(value={ "/getRedis"},method={RequestMethod.POST })
	@ApiOperation(value="获取redis值", notes="key，-")
	public RspInfo<String> getRedis(@RequestBody   RedisParam redisParam ) {
		log.info( "---------------redisParam："+JSON.toJSONString(redisParam) );
		RspInfo<String>  rspInfo= new  RspInfo<String>();
		rspInfo.setRspData( ""+redisUtil.get(redisParam.getKey() ));
		rspInfo.setRspCode(0);
		rspInfo.setRspDesc( "获取成功" );
		return rspInfo;
	}


}
